package com.vaasplus.bms.controller;

import com.github.pagehelper.PageInfo;
import com.vaasplus.bms.pojo.User;
import com.vaasplus.bms.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: zhaoss
 */
@Controller
@Tag(name="用户管理模块",description = "用户模块接口")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/user/{uid}")
    @Operation(summary = "用户模块-根据用户id查询用户信息")

    @Parameters({
        @Parameter(name = "uid",description = "查询参数-用户uid",required = true)
    })
    @ResponseBody
    public User select(@PathVariable Integer uid){
        System.out.println("启动服务器之后修改了代码！！88888888");
        return userService.findOneUser(uid);
    }

    @PostMapping("/user")
    @Operation(summary = "用户模块-保存用户信息")
    @Parameter(name = "user",description = "用户信息",required = true)
    @ResponseBody
    public int save(@RequestBody User user){
        return userService.save(user);
    }

    @PutMapping("/user")
    @Operation(summary = "用户模块-更新用户信息")
    @ResponseBody
    public int update(@RequestBody User user){
        return userService.update(user);
    }

    @DeleteMapping("/user/{uid}")
    @Operation(summary = "用户模块-根据用户id删除用户信息")
    @ResponseBody
    public int delete(@PathVariable Integer uid){
        return userService.deleteUserByUid(uid);
    }


    @GetMapping("/user/list")
    @ResponseBody
    public PageInfo<User> selectAll(int pageNum,int pageSize){
        return userService.findAllUsers(pageNum,pageSize);
    }
}
